/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

package inet.dao;

import inet.entity.Company;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.util.ArrayList;
import java.util.List;

/**
 *
 * @author MiSoKo
 */
public class CompanyDAO extends BaseDAO{
    //Hiển thị danh sách công ty
        //Hiển thị tất cả
        public List<Company> getAll() {
        Connection conn = null;
        PreparedStatement ps = null;
        ResultSet rs = null;
        String sql = null;
        List<Company> lstCom = null;
        try {
            sql = "SELECT * FROM DEPARTMENTS";
            conn = getConnection();
            ps = conn.prepareStatement(sql);
            rs = ps.executeQuery();
            Company com = null;
            while (rs.next()) {
                com = new Company();
                if (lstCom == null) {
                    lstCom = new ArrayList<Company>();
                }
                int i = 1;
                com.setCom_id(rs.getBigDecimal(i++));
                com.setCom_name(rs.getString(i++));
                com.setAddress(rs.getString(i++));
                lstCom.add(com);
            }
            return lstCom;
        } catch (Exception ex) {
            System.out.println("Error in sql: " + sql);
            ex.printStackTrace();
        } finally {
            releaseConnection(conn, ps, rs);
        }
        return null;
    }
}
